package com.iengine.services.api.command;

import com.caucho.hessian.client.HessianProxyFactory;
import com.iengine.services.api.utils.Constant;
import com.iengine.services.api.utils.SysConfigUtil;
import com.ingine.data.pojo.HReply;
import com.ingine.data.service.intf.IDataServer;

import java.net.MalformedURLException;
import java.util.Map;

public abstract class AbstractPhoneApiCommand extends AbstractApiCommand {

    /**
     * 格式化参数列表
     * @param params 输入参数
     * @param result 匹配结果
     * @return 参数格式化后的IResult对象实例
     */
    protected abstract Map formatArgs(Map map,Map nlpParams);

    @Override
    protected Map getFormatResult(Map map) {
    	Map nlpParams = (Map) map.get(Constant.FIELD_NLPPARAMS);
    	
    	/*Map nlpParams = new HashMap<String, Object>();*/
    	map = formatArgs(map,nlpParams);
        return map;

    }

    public HReply getRemoteData(Map map, Map nlpParams){

    	
    	
    	HessianProxyFactory factory = new HessianProxyFactory();
    	HReply result = null;
    	try {
//			IDataServer service = (IDataServer) factory.create(IDataServer.class, "http://data.smallzhi.com:8280/DataServer/DataServer");
			IDataServer service = (IDataServer) factory.create(IDataServer.class, SysConfigUtil.getProp("dataserver_url"));
			result = service.queryDataObject(this.processQuery(map, nlpParams));
		} catch (MalformedURLException e) {
			e.printStackTrace();
		}
		return result;
    }
    
    public String processQuery(Map map, Map nlpParams){
    	return  "";
    }
    
    /**
     * 获取分类类型
     * @return
     */
	public abstract String getCommandType() ;

	public abstract String getCommandValueType() ;

	public abstract boolean isDirectReturn() ;
}
